<template>
  <div>
    <template v-for="(item, index) in options">
      <template v-if="values.includes(item.raw.dictValue)">
        <span
          v-if="item.raw.listClass == 'default' || item.raw.listClass == ''"
          :key="item.dictValue"
          :index="index"
          :class="item.raw.cssClass"
          >{{ item.raw.dictLabel }}</span
        >
        <el-tag
          v-else
          :key="item.raw.dictValue"
          :index="index"
          :type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
          :class="item.raw.cssClass"
        >
          {{ item.raw.dictLabel }}
        </el-tag>
      </template>
    </template>
  </div>
</template>

<script>
export default {
  name: "DictTag",
  props: {
    options: {
      type: Array,
      default: null,
    },
    value: [String, Array, Number],
  },
  computed: {
    values() {
      console.log("字典",this.options)
      let value = this.value
      // value为number类型时 变成字符串 0 --> '0'
      if (typeof value === 'number') {
        value = String(value)
      }
      if (value) {
        return Array.isArray(value) ? value : [ value ];
      } else {
        return [];
      }
    },
  },
};
</script>
<style scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
</style>
